package com.sgb.merchant.view.adapter;

import android.content.Context;
import android.text.TextUtils;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.sgb.link.entity.merchant.SelfProjectList;
import com.sgb.merchant.BR;
import com.sgb.merchant.R;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter2;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * @author: 王彬臣
 * @date: 2021/8/12
 * @Description:
 */
public class SelfInvestmentProjectAdapter extends BaseRecycleAdapter2<SelfProjectList> {

    public ClickBtnListener clickBtnListener;

    public void setClickBtnListener(ClickBtnListener clickBtnListener) {
        this.clickBtnListener = clickBtnListener;
    }

    public SelfInvestmentProjectAdapter(Context context, List<SelfProjectList> datas) {
        super(context, R.layout.merchant_item_self_investment_project, datas);
    }


    @Override
    public void convert(ItemViewHolder holder, SelfProjectList investmentProjectEntity, int position) {
        ViewDataBinding binding = DataBindingUtil.bind(holder.itemView);
        binding.setVariable(BR.viewModel, investmentProjectEntity);
        holder.getView(R.id.tv_edit).setOnClickListener(v -> {
            if (clickBtnListener != null)
                clickBtnListener.editClick(investmentProjectEntity.getNo(), position);
        });
        holder.getView(R.id.tv_del).setOnClickListener(v -> {
            if (clickBtnListener != null)
                clickBtnListener.delClick(investmentProjectEntity.getNo(), position);
        });
        holder.getView(R.id.tv_item_put_away).setOnClickListener(v -> {
            if (clickBtnListener != null)
                clickBtnListener.putAway(investmentProjectEntity.getNo(), position);
        });
        holder.getView(R.id.tv_item_down_away).setOnClickListener(v -> {
            if (clickBtnListener != null)
                clickBtnListener.dowAway(investmentProjectEntity.getNo(), position);
        });
/*        switch (investmentProjectEntity.getItemStatus().getConstantKey()) {
            case "0":
                holder.setImageResource(R.id.iv_state, R.mipmap.merchant_icon_state_no_start);
                holder.setVisible(R.id.tv_edit, true)
                        .setVisible(R.id.rl_btn, true)
                        .setVisible(R.id.v_line, true);
                break;
            case "1":
                holder.setImageResource(R.id.iv_state, R.mipmap.merchant_icon_state_start);
                holder.setVisible(R.id.rl_btn, false)
                        .setVisible(R.id.v_line, false);
                break;
            case "2":
                holder.setImageResource(R.id.iv_state, R.mipmap.merchant_icon_state_end);
                holder.setVisible(R.id.tv_edit, false)
                        .setVisible(R.id.rl_btn, true)
                        .setVisible(R.id.v_line, true);
                break;
        }*/
        if(!TextUtils.isEmpty(investmentProjectEntity.getStatus())) {
            holder.setVisible(R.id.rl_btn,true);
            switch (investmentProjectEntity.getStatus()) {//0 上架 1下架
                case "0":
                    holder.setImageResource(R.id.iv_state, R.mipmap.merchant_icon_putaway)
                            .setVisible(R.id.tv_item_down_away, true)
                            .setVisible(R.id.tv_edit, false)
                            .setVisible(R.id.tv_item_put_away, false)
                            .setVisible(R.id.tv_del, false);
                    break;
                case "1":
                    holder.setImageResource(R.id.iv_state, R.mipmap.merchant_icon_downaway)
                            .setVisible(R.id.tv_item_down_away, false)
                            .setVisible(R.id.tv_edit, true)
                            .setVisible(R.id.tv_item_put_away, true)
                            .setVisible(R.id.tv_del, true);

                    break;
            }
        }
    }

    public interface ClickBtnListener {
        void putAway(long no, int position);

        void dowAway(long no, int position);

        void editClick(long no, int position);

        void delClick(long no, int position);
    }
}
